<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-input
          v-model="query.processInstanceName"
          clearable
          size="small"
          placeholder="流程实例名称"
          style="width: 200px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.startedBy"
          clearable
          size="small"
          placeholder="启动人"
          style="width: 200px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation />
      </div>
      <crudOperation />
    </div>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :data="crud.data"
      style="width: 100%"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="name" label="流程实例名称" />
      <el-table-column prop="businessKey" label="业务主键Key" />
      <el-table-column prop="startUserId" label="启动人" />
      <el-table-column prop="startTime" label="开始时间">
        <template slot-scope="scope">
          <span>{{ scope.row.startTime }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="endTime" label="开始时间">
        <template slot-scope="scope">
          <span>{{ scope.row.endTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-permission="['admin', 'instance:edit', 'instance:del']"
        label="操作"
        width="200px"
        align="center"
      >
        <template slot-scope="scope">
          <el-button
            v-permission="['admin', 'task:edit']"
            style="margin-left: 3px"
            type="text"
            size="mini"
            @click="info(scope.row.id)"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination />
    <!-- 详情 -->
    <process-detail
      v-if="dialogViewVisible"
      :visible.sync="dialogViewVisible"
      :process-instance-id="processInstanceId"
    />
  </div>
</template>

<script>
import CRUD, { presenter, header, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import processDetail from '../components/ProcessDetail'

export default {
  name: 'FlowableMyProcess',
  components: { processDetail, pagination, crudOperation, rrOperation },
  cruds() {
    return CRUD({ title: '流程实例', url: 'api/flowable/instance/involved' })
  },
  mixins: [presenter(), header(), crud()],
  data() {
    return {
      processInstanceId: '',
      dialogViewVisible: false
    }
  },
  created() {
    this.crud.optShow = {
      add: false,
      edit: false,
      del: false,
      download: false
    }
  },
  methods: {
    [CRUD.HOOK.beforeRefresh]() {
      this.crud.query.startByMe = true
      return true
    },
    // 详情
    info(processInstanceId) {
      this.processInstanceId = processInstanceId
      this.dialogViewVisible = true
    }
  }
}
</script>
